<?php
/**
 * set_navibar_sort
 *design by KLLER
 */
!defined('EMLOG_ROOT') && exit('access deined!');
$klNavibarArrTrue = array();
$i = 0;
foreach (unserialize($navibar) as $key => $val)
{
	$klNavibarArrTrue[$i] = array($key => $val);
	$i++;
}
function plugin_setting_view()
{
	global $klNavibarArrTrue;
?>
<script>
	$("#set_navibar_sort").addClass('sidebarsubmenu1');
</script>
<script type="text/javascript" src="../lib/js/jquery/plugin-interface.js"></script>
<script>setTimeout(hideActived,2600);</script>
<div class=containertitle><b>导航排序</b><?php if(isset($_GET['setting'])):?><span class="actived">插件设置完成</span><?php endif;?></div>
<div class=line></div>
<p><font color="green">(注:操作方法和Widgets类似,拖动操作。)</font></p>
<form action="plugin.php?plugin=set_navibar_sort&action=setting" method="post">
<div id="adm_navibar_box" style="width:300px;float:left;">
<ul>
<?php
foreach ($klNavibarArrTrue as $key => $val)
{
	$val = array_values($val);
	$val[0]['hide'] == 'y' ? $navibars[$key] = $val[0]['title'].'|<font color=\'red\'>[隐藏]</font>' : $navibars[$key] = $val[0]['title'];
}
if(is_array($navibars))
{
	foreach ($navibars as $navibar):
	?>
	<li class="sortableitem" id="<?php echo $navibar; ?>">
	<input type="hidden" name="navibars[]" value="<?php echo $navibar; ?>" />
	<?php 
	echo $navibar;
	?>
	</li>
<?php endforeach;
}else{
	echo '<font color=\'red\'>您可能还没有创建新的页面！</font>';
}
?>
</ul>
<div style="margin:10px 40px;"><input type="submit" value="保存导航排序" class="submit" /></div>
</div>
</form>
</div>
<script>
$(document).ready(function(){
	$("#adm_navibar_box ul").mouseover(function(){
		$("#adm_navibar_box ul").Sortable({
			accept: 'sortableitem'
		});
	});
});
</script>
<?php
}

function plugin_setting()
{
	global $klNavibarArrTrue, $DB, $CACHE;
	$navibars = $_POST['navibars'];
	foreach ($navibars as $navibar)
	{
		$navibar = explode('|', $navibar);
		foreach ($klNavibarArrTrue as $key => $val)
		{
			$valbak = $val;
			$val = array_values($val);
			if($val[0]['title'] == $navibar[0])
			{
				$newNavibars[] = $valbak;
			}
		}
	}
	foreach ($newNavibars as $newNavibar)
	{
		foreach ($newNavibar as $key => $val)
		{
			$klNavibar[$key] = $val;
		}
	}
	$newNavibar = serialize($klNavibar);
	$DB->query("UPDATE ".DB_PREFIX."options SET option_value='$newNavibar' where option_name='navibar'");
	$CACHE->mc_options();
}
?>